# coding: utf-8

import jaydebeapi
import os


class Jdbc:

    def query(self, db='default'):
        url = 'jdbc:hive2://10.168.1.188:10000/' + db
        diver = 'org.apache.hive.jdbc.HiveDriver'
        current_dir = os.getcwd() + '/lib/'
        jar_file = [
            current_dir + 'hive-jdbc-3.1.1.jar',
            current_dir + 'commons-logging-1.2.jar',
            current_dir + 'hive-service-3.1.1.jar',
            current_dir + 'hive-service-rpc-3.1.1.jar',
            current_dir + 'libthrift-0.12.0.jar',
            current_dir + 'httpclient-4.5.9.jar',
            current_dir + 'httpcore-4.4.11.jar',
            current_dir + 'slf4j-api-1.7.26.jar',
            current_dir + 'curator-framework-4.2.0.jar',
            current_dir + 'curator-recipes-4.2.0.jar',
            current_dir + 'curator-client-4.2.0.jar',
            current_dir + 'commons-lang-2.6.jar',
            current_dir + 'hadoop-common-3.2.0.jar',
            current_dir + 'httpcore-4.4.11.jar',
            current_dir + 'hive-common-3.1.1.jar',
            current_dir + 'hive-serde-3.1.1.jar',
            current_dir + 'guava-28.0-jre.jar'
        ]
        conn = jaydebeapi.connect(diver, url, jars=jar_file)
        curs = conn.cursor()
        curs.execute("select * from tb1")
        result = curs.fetchall()
        print("result:", result)
        curs.close()
        conn.close()
        return result


sql = Jdbc()
sql.query()
